package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.SwitchSpec;
import com.aplink.generic.xmlparser.XmlPaserUtil;

public class SwitchFormat {
	public static final String DISABLE_GROUP = "disableGroup";
	public static final String IS_CHECKED = "isChecked";
	public static final String TEXT_OFF = "textOff";
	public static final String TEXT_ON = "textOn";
	public static final String VALUE_OFF = "valueOff";
	public static final String VALUE_ON = "valueOn";

	public static SwitchSpec parse(final Node node) {
		final SwitchSpec switchSpec = new SwitchSpec();
		if (node.hasAttributes()) {
			String value = XmlPaserUtil.getAttrValue(node,
					SwitchFormat.VALUE_ON);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setValueOn(value);
			}

			value = XmlPaserUtil.getAttrValue(node, SwitchFormat.VALUE_OFF);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setValueOff(value);
			}
			value = XmlPaserUtil.getAttrValue(node, SwitchFormat.TEXT_ON);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setTextOn(value);
			}

			value = XmlPaserUtil.getAttrValue(node, SwitchFormat.TEXT_OFF);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setTextOff(value);
			}
			value = XmlPaserUtil.getAttrValue(node, SwitchFormat.DISABLE_GROUP);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setDisableGroupID(value);
			}

			value = XmlPaserUtil.getAttrValue(node, SwitchFormat.IS_CHECKED);
			if (!TextUtils.isEmpty(value)) {
				if (value.equalsIgnoreCase("Y")) {
					switchSpec.setChecked(true);
				}
			}
		}
		return switchSpec;
	}
}
